package com.lyz.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class VersionUtil {
	
	public static boolean ge(String version, String targetVersion){
		
		version=version.replace(".", "");
		targetVersion=targetVersion.replace(".", "");
		version=padZero(version,5);
		targetVersion=padZero(targetVersion,5);
		int ver=Integer.parseInt(version);
		int target=Integer.parseInt(targetVersion);
		return ver>=target;
	}
	
	public static String padZero(String source, int targetLength){
		
		StringBuilder sb=new StringBuilder(source);
		for(int i=0;i<targetLength-source.length();i++){
			sb.append("0");
		}
		return sb.toString();
	}
	
	public static Pattern pattern=Pattern.compile("^[0-9](\\.[0-9]{1})*");
	
	public static boolean checkVersion(String version){
		Matcher matcher=pattern.matcher(version);
		return matcher.matches();
	}
	
	public static void main(String[] args){
		
		System.out.println(VersionUtil.ge("5.3.1","5.3"));
		System.out.println(VersionUtil.ge("5.4","5.3"));
		System.out.println(VersionUtil.ge("5.2.1","5.3"));
	}

}
